import axios from 'axios';
import { API_V1_URL } from '@/config/api';
import { AnyObject, HttpResponse, PageResponse } from '@/types/global';
import { AdminUser } from '@/types/adminUser';
import { User } from '@/types/user';
import { UserGame } from '@/types/game';

export interface LoginData {
  phone: string;
  password: string;
}

export interface LoginRes {
  token: string;
}
export function login(data: LoginData) {
  return axios.post<LoginRes>(`${API_V1_URL}/password/login`, data);
}

export function logout() {
  return axios.post<LoginRes>(`${API_V1_URL}/logout`);
}

export function getUserInfo() {
  return axios.get<HttpResponse<AdminUser>>('/api/v1/admin/user/my');
}

export function getUserList(data: AnyObject) {
  return axios.post<HttpResponse<PageResponse<User>>>(
    `${API_V1_URL}/user/page`,
    data
  );
}

export function updateUser(data: AnyObject) {
  return axios.put(`${API_V1_URL}/user/update`, data);
}

export function approveUser(id: string, valid: number) {
  return axios.post(`${API_V1_URL}/user/approve/${id}?valid=${valid}`);
}

export function getUserDetail(id: string) {
  return axios.post<HttpResponse<User>>(`${API_V1_URL}/user/detail?id=${id}`);
}

export function getUserEnrollList(data: AnyObject) {
  return axios.post<HttpResponse<PageResponse<UserGame>>>(
    `${API_V1_URL}/user/game/enroll/page`,
    data
  );
}
